package com.example.zgdemo.service.impl;

import com.example.zgdemo.bean.TGoods;
import com.example.zgdemo.req.SeckillReq;
import com.example.zgdemo.service.GoodsService;
import com.example.zgdemo.service.SeckillService;
import com.example.zgdemo.service.StockService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
public class SeckillServiceImpl implements SeckillService {

    @Autowired
    GoodsService goodsService;
    @Autowired
    StockService stockService;
    @Autowired
    RedisTemplate redisTemplate;

    @Override
    @Transactional
    public boolean seckill(SeckillReq req) {
        TGoods goodsById = goodsService.getGoodsById(req.getGoodsId());
        int i = stockService.updateStock(req.getGoodsId(), req.getNum());
        log.info("购买数量{}",i);
        return true;
    }
}
